﻿using Microsoft.Extensions.Logging;

namespace Unity.Logger.Providers
{
    [ProviderAlias("ProcessorLogger")]
    public class ProcessorLoggerProvider : ILoggerProvider
    {
        IAsyncLogProcessor processor;

        public ProcessorLoggerProvider(IAsyncLogProcessor processor)
        {
            this.processor = processor;
        }

        public ILogger CreateLogger(string categoryName)
        {
            return new AsyncProcessLog(categoryName, this.processor);
        }

        public void Dispose()
        {
            this.processor.DisposeAsync().AsTask().Wait();
        }
    }
}
